/*
2021-8-4
https://www.acwing.com/problem/content/100/
*/
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>

using namespace std;
typedef long long ll;

struct node
{
    ll x,y;
};

node get(ll n,ll a)
{
    if(n==0) return {0,0};
    ll block=1ll<<2*n-2,len=1ll<<n-1;
    auto pa=get(n-1,a%block);
    int z=a/block;
    ll x=pa.x,y=pa.y;
    
    if(z==0) return {y,x};
    else if(z==1) return {x,y+len};
    else if(z==2) return {x+len,y+len};
    else return {2*len-y-1,len-x-1};
    
}

int main()
{
    int T;
    cin>>T;
    while(T--)
    {
        ll n,a,b;
        cin>>n>>a>>b;
        auto pa=get(n,a-1);
        auto pb=get(n,b-1);
        double dx=pa.x-pb.x,dy=pa.y-pb.y;
        
        printf("%.0lf\n",sqrt(dx*dx+dy*dy)*10);
        
    }
    return 0;
}

